import type { Product, ProductDetail, ProductPageParams, ProductParams, ProductUpdateStatusParams } from '@/models/product'
import type { CommonResult, CommonPage } from '@/models/request'
import request, { ContentTypeEnum } from '@/utils/request'
export function fetchList(params: ProductPageParams) {
  return request<CommonPage<Product>>({
    url: '/product/list',
    method: 'get',
    params: params,
  })
}

export function fetchSimpleList(params: { keyword: string }) {
  return request<CommonResult<Product[]>>({
    url: '/product/simpleList',
    method: 'get',
    params: params,
  })
}

export function updateDeleteStatus(params: { ids: string; deleteStatus: number }) {
  return request<CommonResult>({
    url: '/product/update/deleteStatus',
    method: 'post',
    params: params,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function updateNewStatus(params: { ids: string; newStatus: number }) {
  return request<CommonResult>({
    url: '/product/update/newStatus',
    method: 'post',
    params: params,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function updateRecommendStatus(params: { ids: string; recommendStatus: number }) {
  return request<CommonResult>({
    url: '/product/update/recommendStatus',
    method: 'post',
    params: params,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function updatePublishStatus(params: { ids: string; publishStatus: number }) {
  return request<CommonResult>({
    url: '/product/update/publishStatus',
    method: 'post',
    params: params,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function createProduct(data: ProductParams) {
  return request<CommonResult>({
    url: '/product/create',
    method: 'post',
    data: data,
  })
}

export function updateProduct(data: ProductParams) {
  return request<CommonResult>({
    url: '/product/update/' + data.id,
    method: 'post',
    data: data,
  })
}

export function getProduct(id: number) {
  return request<CommonResult<ProductDetail>>({
    url: '/product/updateInfo/' + id,
    method: 'get',
  })
}

export function productUpdateVerifyStatus(data: ProductUpdateStatusParams) {
  return request<CommonResult>({
    url: '/product/update/verifyStatus',
    method: 'post',
    data,
  })
}
